﻿namespace PornSite
{
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using PornSite.Web;
    using System.ServiceModel.DomainServices.Client;

    /// <summary>
    /// <see cref="Page"/> class to present information about the current application.
    /// </summary>
    public partial class About : Page
    {
        PornSite.Web.DomainServicePorn context = new DomainServicePorn();
        public About()
        {
            InitializeComponent();
            
            this.Title = ApplicationStrings.AboutPageTitle;
        }

        /// <summary>
        /// Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void folderDomainDataSource_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void aspnet_UsersDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void photoDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void foldersDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (foldersDataGrid.SelectedItem != null)
            {
                var selected = (Folder)foldersDataGrid.SelectedItem;
                int id = selected.FolderId;
                context.Load(context.GetPublicPhotosQuery(id)).Completed += (s, a) =>
                {
                    LoadOperation<Photo> photos = (LoadOperation<Photo>)s;
                    this.photoRadGridView.ItemsSource = photos;
                };
            }
        }
    }
}